package mytest.lxpFunnyTest;

import lombok.Data;
import mytest.lxpFunnyTest.domain.vo.MyKeyValue;
import mytest.lxpFunnyTest.utils.KeyBoardUtil;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.util.Objects;

@Data
class RobotDemo {

    private Robot robot = null;

    public RobotDemo() {
        try {
            robot = new Robot();
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }

    /**
     * 模拟键盘输入abc
     */
    public void keyBoardDemo(String ...to) {

        for (String s : to) {
            int keyCode=KeyBoardUtil.find(s);
            robot.keyPress(keyCode);
            robot.keyRelease(keyCode);
        }

//        robot.keyRelease(KeyEvent.VK_C);
    }

    //重载键盘操作 长按的操作
    public void keyBoardDemo(int i,String ...to) {
        int keyCode;
        for (String s : to) {
            keyCode=KeyBoardUtil.find(s);
            robot.keyPress(keyCode);
        }

//        for (String s : to) {
//            keyCode=KeyBoardUtil.find(s);
//            robot.keyRelease(keyCode);
//        }
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        for (int i1 = to.length - 1; i1 >= 0; i1--) {
            keyCode=KeyBoardUtil.find(to[i]);
            robot.keyRelease(keyCode);
        }

    }
    /**
     * 移动鼠标位置
     */
    public void mouseDemo(int x,int y) {
        robot.mouseMove(x, y);

        robot.mousePress(KeyEvent.BUTTON1_MASK);
        try {
            Thread.sleep(20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        robot.mouseRelease(KeyEvent.BUTTON1_MASK);
    }

    public void delay(int milliseconds) {
        robot.delay(milliseconds);
    }


}